<template>
  <div>
    <Dog :arr="arr" @dogName="dogNameHandler"></Dog>
    <br />
    <h3>你喜欢的狗狗：</h3>
    <ul>
      <li v-for="(item,index) in liArr" :key="index"> {{item}} </li>
    </ul>
  </div>
</template>

<script>
import Dog from "./components/4-Dog.vue";

export default {
  components: {
    Dog,
  },

  data() {
    return {
      arr: [
        {
          dogImgUrl:
            "http://nwzimg.wezhan.cn/contents/sitefiles2029/10146688/images/21129958.jpg",
          dogName: "博美",
        },
        {
          dogImgUrl:
            "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1224576619,1307855467&fm=26&gp=0.jpg",
          dogName: "泰迪",
        },
        {
          dogImgUrl:
            "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2967740259,1518632757&fm=26&gp=0.jpg",
          dogName: "金毛",
        },
        {
          dogImgUrl:
            "https://pic1.zhimg.com/80/v2-7ba4342e6fedb9c5f3726eb0888867da_1440w.jpg?source=1940ef5c",
          dogName: "哈士奇",
        },
        {
          dogImgUrl:
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Fbao%2Fuploaded%2Fi3%2F2467722902%2FO1CN01C1dnq21XJA1koZM7z_%21%212467722902.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643986453&t=b3cf3800594d204b5a48cc800223f344",
          dogName: "阿拉斯加",
        },
        {
          dogImgUrl:
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Feuro-premium.cn%2Fsites%2Fdefault%2Ffiles%2F2018%2F03%2F2018-03-02-602.jpg&refer=http%3A%2F%2Feuro-premium.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643986489&t=b4228256614414076d38047cd1e538b5",
          dogName: "萨摩耶",
        },
      ],
      liArr:[]
    };
  },

  methods: {
    dogNameHandler(dogName) {
      if(this.liArr.indexOf(dogName)>=0) return alert('已经选了哦')
      this.liArr.push(dogName)
    },
  },
};
</script>

<style lang="css" scoped>
h3,
ul {
  float: left;
}
</style>